#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define all(x) (x).begin(),(x).end()
typedef long long ll;

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<VI> VVI;

typedef pair<int,int> PII;
typedef vector<PII> VPII;
#define X first
#define Y second
#define mp make_pair

#define two(x) (1<<(x))
#define twoll(x) ((long long)1<<(x))
#define contain(s,x) (((s)&two(x))!=0)
#define containll(s,x) (((s)&twoll(x))!=0)

#define db(a) cout << #a << "=" << a << " "
#define dbn cout << endl
#define sqr(x) (x)*(x)

string STR(int n) { char tmp[20]; sprintf(tmp,"%d",n); return tmp; }
int INT(string s) { return atoi(s.c_str()); }
template <class Ty, class Tx> Ty to(const Tx &x) { Ty y; stringstream ss; ss<<x; ss>>y; return y; }

const int INF = 1000000007;
const double EPS = 1e-10;

char buf[1<<20];
int TC;

int W,H,N;
int minW[50001];
int minH[50001];
int maxW[50001];
int maxH[50001];

int main() {
#define SUBMIT 0
#if !SUBMIT
	freopen("DATA.in", "rt", stdin);
	freopen("DATA.ou", "wt", stdout);
#endif

	gets(buf); TC = atoi(buf);
	
	while (TC--) {
		scanf("%d%d%d",&W,&H,&N);
		memset(minW,-1,sizeof(minW));
		memset(minH,-1,sizeof(minH));
		memset(maxW,-1,sizeof(maxW));
		memset(maxH,-1,sizeof(maxH));
		
		for (int i = 0; i < N; ++i) {
			int x,y;
			scanf("%d%d",&x,&y);
			int minx = max(0,x-1);
			int miny = max(0,y-1);
			int maxx = min(W,x+1);
			int maxy = min(H,y+1);
			for (int i = minx; i <= maxx; ++i) {
				if (minH[i] == -1)
					minH[i] = miny, maxH[i] = maxy;
				else
					minH[i] = min(minH[i],miny), maxH[i] = max(maxH[i],maxy);
			}
			for (int i = miny; i <= maxy; ++i) {
				if (minW[i] == -1)
					minW[i] = minx, maxW[i] = maxx;
				else
					minW[i] = min(minW[i],minx), maxW[i] = max(maxW[i],maxx);
			}
		}
		
		int add = INF;
		for (int i = 0; i <= W; ++i) {
			if (minH[i] == -1)
				continue;
			add = min(add,H-(maxH[i]-minH[i]));
		}
		for (int i = 0; i <= H; ++i) {
			if (minW[i] == -1)
				continue;
			add = min(add,W-(maxW[i]-minW[i]));
		}
		int res = 0;
		for (int i = 0; i < W; ++i) {
			if (minH[i] == -1)
				continue;
			int a = maxH[i]-minH[i];
			int b = maxH[i+1]-minH[i+1];
			res += min(a,b);
		}
		printf("%d\n",res+add);
	}

	return 0;
}





